package servlet;

import javax.servlet.RequestDispatcher;
import javax.servlet.ServletException;
import javax.servlet.ServletRequest;
import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import java.io.IOException;
import java.util.Arrays;

public class servlet_request extends HttpServlet {
    public servlet_request() {
        super();
    }

    @Override
    protected void doGet(HttpServletRequest req, HttpServletResponse resp) throws ServletException, IOException {
//        req.setCharacterEncoding("UTF-8");
        String header = req.getHeader("User-Agent");
        System.out.println("请求头信息: "+header);
       String method =  req.getMethod();
        System.out.println("请求方式:"+method);
        String uri = req.getRequestURI();
        System.out.println("URI="+uri);
        StringBuffer url =  req.getRequestURL();
        System.out.println("URL="+url);
       String host =  req.getRemoteHost();
        System.out.println("访问主机: "+host);
        String user = req.getParameter("user");
        System.out.println("用户名: "+user);
        String password = req.getParameter("password");
        System.out.println("密码: "+password);
        String[] chexckbox=req.getParameterValues("checkbox");
        System.out.println("复选框: "+ Arrays.toString(chexckbox));
        String auth = req.getHeader("Accept-Encoding");
        System.out.println("encoding: "+auth);
        System.out.println("----------------");
        //请求转发
        System.out.println("柜台一的材料: "+user);
        req.setAttribute("key","章");
        RequestDispatcher disp = req.getRequestDispatcher("/forwar");
        //转发
        disp.forward(req,resp);
    }

    @Override
    protected void doPost(HttpServletRequest req, HttpServletResponse resp) throws ServletException, IOException {
        doGet(req, resp);
    }
}
